package com.longshine.plc.ui;

import com.longshine.util.NumberUtil;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import org.jdesktop.layout.GroupLayout;
import org.jdesktop.layout.GroupLayout.ParallelGroup;
import org.jdesktop.layout.GroupLayout.SequentialGroup;

public class EquipPowerPanel extends OwnPanel
{
  private ButtonGroup buttonGroup1;
  private ButtonGroup buttonGroup2;
  private ButtonGroup buttonGroup3;
  private JButton jButton6;
  private JButton jButton7;
  private JLabel jLabel13;
  private JLabel jLabel14;
  private JLabel jLabel15;
  private JLabel jLabel17;
  private JLabel jLabel18;
  private JRadioButton jRadioButton23;
  private JRadioButton jRadioButton24;
  private JRadioButton jRadioButton25;
  private JRadioButton jRadioButton26;
  private JRadioButton jRadioButton27;
  private JRadioButton jRadioButton28;
  private JTextField jTextField5;
  private JTextField jTextField6;

  public String getHexData()
  {
    return jTextField6.getText();
  }

  public void init() {
    this.title = "设备电路状态";
    ActionListener l = new ActionListener()
    {
      public void actionPerformed(ActionEvent e) {
        Object o = e.getSource();
        if ((o instanceof JRadioButton))
          EquipPowerPanel.this.radioChanged();
      }
    };
    this.jRadioButton23.setSelected(true);
    this.jRadioButton25.setSelected(true);
    this.jRadioButton27.setSelected(true);
    this.jRadioButton23.addActionListener(l);
    this.jRadioButton24.addActionListener(l);
    this.jRadioButton25.addActionListener(l);
    this.jRadioButton26.addActionListener(l);
    this.jRadioButton27.addActionListener(l);
    this.jRadioButton28.addActionListener(l);
    radioChanged();
  }
  public void radioChanged() {
    String binStr = "";
    binStr =  (this.jRadioButton23.isSelected() ? "1" : "0") + binStr;
    binStr =  (this.jRadioButton25.isSelected() ? "1" : "0") + binStr;
    binStr =  (this.jRadioButton27.isSelected() ? "1" : "0") + binStr;
    binStr =  "0000000000000" + binStr;
    this.jTextField5.setText(binStr);
    this.jTextField6.setText(NumberUtil.binary2Hex(binStr, 2));
  }

  public EquipPowerPanel()
  {
    initComponents();
  }

  private void initComponents()
  {
    this.buttonGroup1 = new ButtonGroup();
    this.buttonGroup2 = new ButtonGroup();
    this.buttonGroup3 = new ButtonGroup();
    this.jRadioButton27 = new JRadioButton();
    this.jRadioButton28 = new JRadioButton();
    this.jLabel17 = new JLabel();
    this.jTextField5 = new JTextField();
    this.jRadioButton24 = new JRadioButton();
    this.jButton6 = new JButton();
    this.jRadioButton26 = new JRadioButton();
    this.jButton7 = new JButton();
    this.jLabel18 = new JLabel();
    this.jLabel13 = new JLabel();
    this.jTextField6 = new JTextField();
    this.jRadioButton23 = new JRadioButton();
    this.jLabel15 = new JLabel();
    this.jRadioButton25 = new JRadioButton();
    this.jLabel14 = new JLabel();

    this.buttonGroup3.add(this.jRadioButton27);
    this.jRadioButton27.setText("1");

    this.buttonGroup3.add(this.jRadioButton28);
    this.jRadioButton28.setText("0");

    this.jLabel17.setText("二进制数据");

    this.buttonGroup1.add(this.jRadioButton24);
    this.jRadioButton24.setText("0");

    this.jButton6.setText("确定");

    this.buttonGroup2.add(this.jRadioButton26);
    this.jRadioButton26.setText("0");

    this.jButton7.setText("确定");

    this.jLabel18.setText("十六进制数据");

    this.jLabel13.setText("上位机断路器状态");

    this.buttonGroup1.add(this.jRadioButton23);
    this.jRadioButton23.setText("1");

    this.jLabel15.setText("干燥机断路器状态");

    this.buttonGroup2.add(this.jRadioButton25);
    this.jRadioButton25.setText("1");

    this.jLabel14.setText("空压机断路器状态");

    GroupLayout layout = new GroupLayout(this);
    setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(1)
      .add(layout.createSequentialGroup()
      .add(36, 36, 36)
      .add(layout.createParallelGroup(1)
      .add(this.jLabel13)
      .add(this.jLabel14)
      .add(this.jLabel15)
      .add(this.jLabel17)
      .add(this.jLabel18))
      .add(70, 70, 70)
      .add(layout.createParallelGroup(1, false)
      .add(layout.createSequentialGroup()
      .add(layout.createParallelGroup(1)
      .add(this.jRadioButton23)
      .add(this.jRadioButton25)
      .add(this.jRadioButton27))
      .add(126, 126, 126)
      .add(layout.createParallelGroup(1)
      .add(this.jRadioButton28)
      .add(this.jRadioButton26)
      .add(this.jRadioButton24)))
      .add(this.jTextField5)
      .add(this.jTextField6))
      .add(18, 18, 18)
      .add(layout.createParallelGroup(1)
      .add(this.jButton6)
      .add(this.jButton7))
      .addContainerGap(-1, 32767)));

    layout.setVerticalGroup(
      layout.createParallelGroup(1)
      .add(layout.createSequentialGroup()
      .add(39, 39, 39)
      .add(layout.createParallelGroup(3)
      .add(this.jLabel13)
      .add(this.jRadioButton23)
      .add(this.jRadioButton24))
      .add(28, 28, 28)
      .add(layout.createParallelGroup(3)
      .add(this.jLabel14)
      .add(this.jRadioButton25)
      .add(this.jRadioButton26))
      .add(32, 32, 32)
      .add(layout.createParallelGroup(2)
      .add(layout.createParallelGroup(3)
      .add(this.jRadioButton27)
      .add(this.jRadioButton28))
      .add(this.jLabel15))
      .add(51, 51, 51)
      .add(layout.createParallelGroup(3)
      .add(this.jTextField5, -2, -1, -2)
      .add(this.jLabel17)
      .add(this.jButton6))
      .add(30, 30, 30)
      .add(layout.createParallelGroup(3)
      .add(this.jLabel18)
      .add(this.jTextField6, -2, -1, -2)
      .add(this.jButton7))
      .addContainerGap(-1, 32767)));
  }
}